package qq_talk.test;

import java.util.Date;
import java.util.List;

public class IdsThread implements Runnable{

	private List<Integer> ids = null;
	private String code = null;
	
	
	public IdsThread(List<Integer> ids, String code) {
		super();
		this.ids = ids;
		this.code = code;
	}

	public void addIds() {
		ids.add(new Date().getSeconds());
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public void removeIds() {
		ids.remove(0);
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public void showIds() {
		System.out.println("===show===");
		for(Integer id : ids) {
			System.out.println("id="+id);
		}
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void run() {
		while(true) {
			if(code.equals("add")) {
				addIds();
			}else if(code.equals("remove")) {
				removeIds();
			}
			else if(code.equals("show")) {
				showIds();
			}
		}
		
		
	}

}
